package com.amumu.drama.common.constant;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;

/**
 * @author sunzhuang
 * @date 2024/5/13 20:32
 * @slogan 天下风云出我辈, 一入代码岁月催
 * @desc 订单类型
 */
@Getter
public enum OrderTypeEnum {
    /**
     * 订单发货类型
     */
    INTERFACE_DELIVERY(0, "接口"),
    MANUAL_DELIVERY(1, "人工"),
    INTERFACE2MANUAL_DELIVERY(2, "接口转人工"),
    MANUAL2INTERFACE_DELIVERY(3, "人工转接口"),
    ;

    private Integer code;

    private String desc;

    private static Map<Integer, OrderTypeEnum> UNINDEX = Maps.uniqueIndex(Arrays.asList(values()), OrderTypeEnum::getCode);

    OrderTypeEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static OrderTypeEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        return UNINDEX.getOrDefault(code, null);
    }

    public static boolean isInterface(Integer orderType) {
        return Lists.newArrayList(INTERFACE_DELIVERY.getCode(), MANUAL2INTERFACE_DELIVERY.getCode()).contains(orderType);
    }
    public static boolean isManual(Integer orderType) {
        return Lists.newArrayList(MANUAL_DELIVERY.getCode(), INTERFACE2MANUAL_DELIVERY.getCode()).contains(orderType);
    }
}
